package com.fone.player.activity.local;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.fone.player.R;
import com.fone.player.activity.local.adapter.LocalEncryptionMediaAdatper;
import com.fone.player.entity.MediaFile;
import com.fone.player.play.FonePlayerActivity;
import com.fone.player.play.PlayerFrom;
import com.fone.player.util.L;
import com.fone.player.view.MyLinearLayout;

public class LocalPrivateMediaFragment extends Fragment implements OnClickListener {
	private String TAG = "LocalPrivateMediaFragment";
	private List<MediaFile> mPrivateVideos;
	private List<Boolean> mCheckBoxs;
	private View mView;
	private String FILE_NAME = "FILE_PASSWORSD";
	private String LOCAL_PASSWORD = "local_password";
	private boolean needInitData = true;// 是否需要重新整理界面

	private View keyBoardView;

	private List<String> numbers;

	private List<EditText> mEditTexts;
	private Handler mHandler;

	public boolean shouldEncrptyMedia = false; // 主要用于当点击加密时，还没有创建私人库，跳到私人页面
												// 创建私人库后，是否需要直接对视频加密
	public boolean shouldScrollBcakPage = false;// 主要用于当点击加密时，还没有创建私人库，跳到私人页面
												// 后，点击取消创建私人库后 是否需要返回到原来的页面
	public int mFromPageId;
	public int mEncrptyMediaPosition;

	// 当前页面的显示模式 ：1、未创建私人库 2、设置密码 3、输入密码 4、无加密视频 5、有加密视频
	private final static int PRIVATE_MODE_NO_LIBRARY = 1, PRIVATE_MODE_SET_PASSWORD = 2, PRIVATE_MODE_INPUT_PASSWORD = 3, PRIVATE_MODE_NO_PRIVATE_MEDIA = 4, PRIVATE_MODE_HAS_PRIVATE_MEDIA = 5, PRIVATE_MODE_CLOSE_LIBRARY = 6;
	private int View_Mode = 0;

	public void setHandler(Handler mHandler) {

		this.mHandler = mHandler;
	}

	// 是否设置密码
	private boolean hasPassword;

	// 私人视频库密码
	private String localPassword;
	// 是否取消 私人视频库密码
	private boolean isCanclePassWord;
	private View private_all_bottom;

	private TextView tv_private_password_desc;

	private View ll_local_save_bottom;

	private ListView lv_local_private_videos;

	private View rl_no_password_video;

	private MyLinearLayout ll_password;

	private View rl_input_password;
	private LocalEncryptionMediaAdatper mPrivateVideosAdapter;
	private CheckBox cb_local_private_switch;
	private SharedPreferences sp;
	private RelativeLayout rl_local_no_library;
	private int NO_LIBRARY_VIEW = 0, INPUT_PASSWORD_VIEW = 1, SHOW_PRIVATE_VIDEOS_VIEW = 2;
	private int mCurrentViewID = NO_LIBRARY_VIEW;

	private LocalActivity mLocalActivity;
	private TextView tv_save, tv_cancle;

	public LocalPrivateMediaFragment() {

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onResume() {
		super.onResume();
		needInitData = true;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		mView = LayoutInflater.from(getActivity()).inflate(R.layout.personal_local_private_file_view, null);
		initView();
		initData();
		if (mPrivateVideos != null) {
			notifyData(mPrivateVideos.size());
		}
		return mView;
	}

	public List<MediaFile> getPrivateVideos() {
		return mPrivateVideos;
	}

	public void setPrivateVideos(List<MediaFile> mVideos) {

		this.mPrivateVideos = mVideos;
		L.i(TAG, "mPrivateVideos size:" + mPrivateVideos.size());
	}

	private void initView() {
		mCheckBoxs = new ArrayList<Boolean>();
		mCheckBoxs.add(false);
		numbers = new ArrayList<String>();
		cb_local_private_switch = (CheckBox) mView.findViewById(R.id.cb_local_private_switch);
		rl_local_no_library = (RelativeLayout) mView.findViewById(R.id.rl_local_no_library);
		ll_password = (MyLinearLayout) mView.findViewById(R.id.ll_password);
		rl_input_password = mView.findViewById(R.id.rl_password);
		ll_local_save_bottom = (LinearLayout) mView.findViewById(R.id.ll_local_private);
		private_all_bottom = mView.findViewById(R.id.rl_local_bottom);
		tv_save = (TextView) mView.findViewById(R.id.tv_local_save);
		tv_cancle = (TextView) mView.findViewById(R.id.tv_local_cancle);
		tv_save.setOnClickListener(this);
		tv_cancle.setOnClickListener(this);
		tv_private_password_desc = (TextView) mView.findViewById(R.id.tv_private_password_desc);
		lv_local_private_videos = (ListView) mView.findViewById(R.id.lv_local_password_videos);
		lv_local_private_videos.setVisibility(View.GONE);
		mPrivateVideosAdapter = new LocalEncryptionMediaAdatper(getActivity(), mPrivateVideos, mCheckBoxs, lv_local_private_videos, mHandler);
		lv_local_private_videos.setAdapter(mPrivateVideosAdapter);
		// L.i(TAG, "init view mPrivateVideos size:" + mPrivateVideos.size());
		VideosItemClickListener ItemListener = new VideosItemClickListener(mPrivateVideos);
		lv_local_private_videos.setOnItemClickListener(ItemListener);
		rl_no_password_video = mView.findViewById(R.id.rl_no_password_video);

		EditText et_first = (EditText) mView.findViewById(R.id.et_first);
		EditText et_second = (EditText) mView.findViewById(R.id.et_second);
		EditText et_third = (EditText) mView.findViewById(R.id.et_third);
		EditText et_forth = (EditText) mView.findViewById(R.id.et_forth);

		keyBoardView = (View) mView.findViewById(R.id.key_board);
		Button btn_zero = (Button) keyBoardView.findViewById(R.id.num_zero);
		Button btn_one = (Button) keyBoardView.findViewById(R.id.num_one);
		Button btn_two = (Button) keyBoardView.findViewById(R.id.num_two);
		Button btn_three = (Button) keyBoardView.findViewById(R.id.num_three);
		Button btn_four = (Button) keyBoardView.findViewById(R.id.num_four);
		Button btn_five = (Button) keyBoardView.findViewById(R.id.num_five);
		Button btn_six = (Button) keyBoardView.findViewById(R.id.num_six);
		Button btn_seven = (Button) keyBoardView.findViewById(R.id.num_seven);
		Button btn_eight = (Button) keyBoardView.findViewById(R.id.num_eight);
		Button btn_nine = (Button) keyBoardView.findViewById(R.id.num_nine);
		Button btn_cancle = (Button) keyBoardView.findViewById(R.id.num_cancle);
		Button btn_delete = (Button) keyBoardView.findViewById(R.id.num_delete);

		KeyBoardClickListener keyBoardListener = new KeyBoardClickListener();
		btn_zero.setOnClickListener(keyBoardListener);
		btn_one.setOnClickListener(keyBoardListener);
		btn_two.setOnClickListener(keyBoardListener);
		btn_three.setOnClickListener(keyBoardListener);
		btn_four.setOnClickListener(keyBoardListener);
		btn_five.setOnClickListener(keyBoardListener);
		btn_six.setOnClickListener(keyBoardListener);
		btn_seven.setOnClickListener(keyBoardListener);
		btn_eight.setOnClickListener(keyBoardListener);
		btn_nine.setOnClickListener(keyBoardListener);
		btn_cancle.setOnClickListener(keyBoardListener);
		btn_delete.setOnClickListener(keyBoardListener);
		ll_password.setOnClickListener(this);
		mEditTexts = new ArrayList<EditText>();
		mEditTexts.add(et_first);
		mEditTexts.add(et_second);
		mEditTexts.add(et_third);
		mEditTexts.add(et_forth);
		EditTextWatcher watcher = new EditTextWatcher();
		et_forth.addTextChangedListener(watcher);
		hasPassWord();
		CheckBoxChangeListener BoxChangeListener = new CheckBoxChangeListener();
		cb_local_private_switch.setOnCheckedChangeListener(BoxChangeListener);

		// if (!mLocalActivity.shouldInputPassWord) {
		// rl_input_password.setVisibility(View.GONE);
		// private_all_bottom.setVisibility(View.GONE);
		//
		// }
	}

	public void setLocativity(LocalActivity activity) {
		this.mLocalActivity = activity;
	}

	public void notifyData(int VideoNum) {
		if (mPrivateVideosAdapter != null) {
			mPrivateVideosAdapter.notifyDataSetChanged();
		}
		if (VideoNum > 0 && mCurrentViewID == SHOW_PRIVATE_VIDEOS_VIEW) {
			changeViewMode(PRIVATE_MODE_HAS_PRIVATE_MEDIA);
		} else if (View_Mode == PRIVATE_MODE_HAS_PRIVATE_MEDIA) {
			if (hasPassword) {
				changeViewMode(PRIVATE_MODE_NO_PRIVATE_MEDIA);
			}
		}
	}

	// 每次切换到私人页面时，都要重新输入密码
	public void initData() {
		if (mView != null) {
			if (hasPassword) {
				mCurrentViewID = INPUT_PASSWORD_VIEW;
				changeViewMode(PRIVATE_MODE_INPUT_PASSWORD);
			} else {
				if (shouldEncrptyMedia) {
					changeViewMode(PRIVATE_MODE_SET_PASSWORD);
				} else {
					changeViewMode(PRIVATE_MODE_NO_LIBRARY);
				}
			}
		}
	}

	// 改变当前显示模式
	private void changeViewMode(int ModeType) {
		switch (ModeType) {
		case PRIVATE_MODE_NO_LIBRARY:
			View_Mode = PRIVATE_MODE_NO_LIBRARY;
			String noLibraryDesc = getResources().getString(R.string.local_no_private_video_library);
			tv_private_password_desc.setText(noLibraryDesc);
			rl_input_password.setVisibility(View.GONE);
			rl_local_no_library.setVisibility(View.VISIBLE);
			lv_local_private_videos.setVisibility(View.GONE);
			cb_local_private_switch.setChecked(false);
			rl_no_password_video.setVisibility(View.GONE);
			// 隐藏底部
			ll_local_save_bottom.setVisibility(View.GONE);
			private_all_bottom.setVisibility(View.GONE);
			keyBoardView.setVisibility(View.GONE);
			break;
		case PRIVATE_MODE_SET_PASSWORD:
			View_Mode = PRIVATE_MODE_SET_PASSWORD;
			cb_local_private_switch.setChecked(true);
			String desc = getResources().getString(R.string.local_set_password);
			tv_private_password_desc.setText(desc);
			rl_input_password.setVisibility(View.VISIBLE);
			rl_local_no_library.setVisibility(View.GONE);
			lv_local_private_videos.setVisibility(View.GONE);
			rl_no_password_video.setVisibility(View.GONE);
			// 显示底部（保存按钮）
			tv_save.setVisibility(View.VISIBLE);
			tv_cancle.setVisibility(View.VISIBLE);
			private_all_bottom.setVisibility(View.VISIBLE);
			ll_local_save_bottom.setVisibility(View.VISIBLE);
			keyBoardView.setVisibility(View.GONE);
			if (numbers.size() < 4) {
				tv_cancle.setClickable(false);
				tv_save.setClickable(false);
				tv_cancle.setTextColor(Color.GRAY);
				tv_save.setTextColor(Color.GRAY);
			}
			break;
		case PRIVATE_MODE_INPUT_PASSWORD:
			View_Mode = PRIVATE_MODE_INPUT_PASSWORD;
			cb_local_private_switch.setChecked(true);
			String Inputdesc = getResources().getString(R.string.local_input_password);
			tv_private_password_desc.setText(Inputdesc);
			rl_input_password.setVisibility(View.VISIBLE);
			rl_local_no_library.setVisibility(View.GONE);
			lv_local_private_videos.setVisibility(View.GONE);
			rl_no_password_video.setVisibility(View.GONE);
			// 隐藏底部
			tv_save.setVisibility(View.GONE);
			tv_cancle.setVisibility(View.GONE);
			ll_local_save_bottom.setVisibility(View.GONE);
			private_all_bottom.setVisibility(View.GONE);
			keyBoardView.setVisibility(View.GONE);
			break;
		case PRIVATE_MODE_NO_PRIVATE_MEDIA:
			View_Mode = PRIVATE_MODE_NO_PRIVATE_MEDIA;
			cb_local_private_switch.setChecked(true);
			mCurrentViewID = SHOW_PRIVATE_VIDEOS_VIEW;
			rl_local_no_library.setVisibility(View.GONE);
			rl_input_password.setVisibility(View.GONE);
			tv_save.setVisibility(View.GONE);
			cb_local_private_switch.setVisibility(View.VISIBLE);
			rl_no_password_video.setVisibility(View.VISIBLE);
			lv_local_private_videos.setVisibility(View.GONE);
			// 隐藏底部
			tv_save.setVisibility(View.GONE);
			tv_cancle.setVisibility(View.GONE);
			ll_local_save_bottom.setVisibility(View.GONE);
			keyBoardView.setVisibility(View.GONE);
			private_all_bottom.setVisibility(View.GONE);
			break;
		case PRIVATE_MODE_HAS_PRIVATE_MEDIA:
			View_Mode = PRIVATE_MODE_HAS_PRIVATE_MEDIA;
			cb_local_private_switch.setChecked(true);
			mCurrentViewID = SHOW_PRIVATE_VIDEOS_VIEW;
			rl_local_no_library.setVisibility(View.GONE);
			rl_input_password.setVisibility(View.GONE);
			tv_save.setVisibility(View.GONE);
			cb_local_private_switch.setVisibility(View.VISIBLE);
			lv_local_private_videos.setVisibility(View.VISIBLE);
			rl_no_password_video.setVisibility(View.GONE);
			// 隐藏底部
			tv_save.setVisibility(View.GONE);
			tv_cancle.setVisibility(View.GONE);
			ll_local_save_bottom.setVisibility(View.GONE);
			private_all_bottom.setVisibility(View.GONE);
			keyBoardView.setVisibility(View.GONE);
			break;
		case PRIVATE_MODE_CLOSE_LIBRARY:
			View_Mode = PRIVATE_MODE_CLOSE_LIBRARY;
			cb_local_private_switch.setChecked(false);
			rl_local_no_library.setVisibility(View.GONE);
			rl_input_password.setVisibility(View.VISIBLE);
			String closeLibraryDesc = getResources().getString(R.string.local_close_private_video_library);
			tv_private_password_desc.setText(closeLibraryDesc);
			rl_no_password_video.setVisibility(View.GONE);
			lv_local_private_videos.setVisibility(View.GONE);
			isCanclePassWord = true;
			// 隐藏底部
			tv_save.setVisibility(View.GONE);
			tv_cancle.setVisibility(View.GONE);
			ll_local_save_bottom.setVisibility(View.GONE);
			private_all_bottom.setVisibility(View.GONE);
			keyBoardView.setVisibility(View.GONE);
			break;
		default:
			break;
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.tv_local_cancle:
			for (EditText et : mEditTexts) {
				et.setText(null);
			}
			numbers.clear();
			tv_cancle.setClickable(false);
			tv_save.setClickable(false);
			tv_cancle.setTextColor(Color.GRAY);
			tv_save.setTextColor(Color.GRAY);
			if (shouldScrollBcakPage) {
				Message ScrollBcakPageMsg = mHandler.obtainMessage();
				ScrollBcakPageMsg.arg1 = mFromPageId;
				ScrollBcakPageMsg.arg2 = -1;
				ScrollBcakPageMsg.what = LocalActivity.MSG_SCROLL_VIEW_PAGER;
				ScrollBcakPageMsg.obj = LocalActivity.PAGE_PRIVATE_MEDIAS;
				mHandler.sendMessage(ScrollBcakPageMsg);
			}
			hideKeyBoardView();
			break;
		case R.id.tv_local_save:

			StringBuilder builder = new StringBuilder();
			for (EditText et : mEditTexts) {
				builder.append(et.getText().toString().trim());
			}
			numbers.clear();
			String password = builder.toString();
			if (password.length() == 4) {
				Editor editor = sp.edit();
				editor.putString(LOCAL_PASSWORD, password);
				editor.commit();
				hasPassWord();
				Toast.makeText(getActivity(), "密码保存成功", Toast.LENGTH_SHORT).show();
				showPrivateVideosView();
			} else {
				Toast.makeText(getActivity(), "请输入四位密码", Toast.LENGTH_SHORT).show();
				for (EditText et : mEditTexts) {
					et.setText(null);
				}
				return;
			}
			if (shouldEncrptyMedia) {
				Message msg = mHandler.obtainMessage();
				msg.what = LocalActivity.MSG_ENCRYPT_MEDIA;
				msg.arg1 = mFromPageId;// 从哪个页面加密的
				msg.arg2 = mEncrptyMediaPosition;
				mHandler.sendMessage(msg);
				shouldEncrptyMedia = false;
				rl_no_password_video.setVisibility(View.GONE);
				lv_local_private_videos.setVisibility(View.VISIBLE);

			}
			break;
		case R.id.ll_password:// 显示键盘
			if (mCurrentViewID == NO_LIBRARY_VIEW) {
				ll_local_save_bottom.setVisibility(View.VISIBLE);
			} else {
				ll_local_save_bottom.setVisibility(View.GONE);
			}
			private_all_bottom.setVisibility(View.VISIBLE);
			keyBoardView.setVisibility(View.VISIBLE);
			break;
		default:
			break;
		}
	}

	private class VideosItemClickListener implements OnItemClickListener {
		private List<MediaFile> list;

		public VideosItemClickListener(List<MediaFile> list) {
			this.list = list;
		}

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			String[] urls = new String[list.size()];
			for (int i = 0; i < list.size(); i++) {
				urls[i] = list.get(i).getMediaFilePath();
			}
			needInitData = false;
			Intent intent = new Intent(getActivity(), FonePlayerActivity.class);
			intent.putExtra("from", PlayerFrom.ENCRYPTION);
			intent.putExtra("index", position);
			intent.putExtra("urls", urls);
			getActivity().startActivity(intent);
		}

	}

	// 判断是否已经设置密码
	private void hasPassWord() {
		sp = getActivity().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
		localPassword = sp.getString(LOCAL_PASSWORD, null);
		for (EditText et : mEditTexts) {
			et.setText(null);
		}
		if (localPassword != null) {
			hasPassword = true;
			rl_local_no_library.setVisibility(View.GONE);
			private_all_bottom.setVisibility(View.GONE);
			String desc = getResources().getString(R.string.local_input_password);
			tv_private_password_desc.setText(desc);
			mCurrentViewID = INPUT_PASSWORD_VIEW;
			cb_local_private_switch.setChecked(true);

		} else {
			hasPassword = false;
			mCurrentViewID = NO_LIBRARY_VIEW;
			private_all_bottom.setVisibility(View.GONE);
			rl_local_no_library.setVisibility(View.VISIBLE);
			keyBoardView.setVisibility(View.GONE);
			ll_local_save_bottom.setVisibility(View.VISIBLE);
			cb_local_private_switch.setChecked(false);
			rl_input_password.setVisibility(View.GONE);
		}

	}

	private class KeyBoardClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {

			case R.id.num_cancle:
				hideKeyBoardView();
				// hasPassWord();

				break;
			case R.id.num_delete:
				if (numbers.size() > 0) {
					numbers.remove(numbers.size() - 1);
				}
				for (int i = 0; i < 4; i++) {
					if (numbers.size() > i) {
						mEditTexts.get(i).setText(numbers.get(i));
					} else {
						mEditTexts.get(i).setText(null);
					}
				}
				break;

			default:
				Button btn = (Button) keyBoardView.findViewById(v.getId());
				L.i(TAG, "number size:" + numbers.size());
				if (numbers.size() < 4) {
					numbers.add(btn.getText().toString());
					for (int j = 0; j < numbers.size(); j++) {
						mEditTexts.get(j).setText(numbers.get(j));
					}
				}
				break;

			}

		}

	}

	private class EditTextWatcher implements TextWatcher {

		String beforeStr = null;
		String afterStr = null;

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count, int after) {
			beforeStr = s.toString().trim();
		}

		@Override
		public void onTextChanged(CharSequence s, int start, int before, int count) {
		}

		@Override
		public void afterTextChanged(Editable s) {
			if (hasPassword) {
				afterStr = s.toString();
				if (beforeStr.length() == 0 && afterStr.length() == 1) {
					StringBuilder builder = new StringBuilder();
					for (EditText et : mEditTexts) {
						builder.append(et.getText().toString().trim());
					}
					String password = builder.toString();
					if (password.equals(localPassword)) {

						if (isCanclePassWord) {// 关闭视频库
							if (mPrivateVideos.size() > 0) {
								Message message = mHandler.obtainMessage();
								message.what = LocalActivity.MSG_DECODE_ALL_MEDIA;
								mHandler.sendMessage(message);
							}
							Editor editor = sp.edit();
							editor.putString(LOCAL_PASSWORD, null);
							editor.commit();
							hasPassWord();
							isCanclePassWord = false;
							changeViewMode(PRIVATE_MODE_NO_LIBRARY);
							// rl_input_password.setVisibility(View.GONE);
							// rl_local_no_library.setVisibility(View.VISIBLE);
							// ll_local_save_bottom.setVisibility(View.GONE);
						} else {// 进入视频库
							getPrivateMedia();
							keyBoardView.setVisibility(View.GONE);
							showPrivateVideosView();
							mCurrentViewID = SHOW_PRIVATE_VIDEOS_VIEW;
						}
						numbers.clear();
						for (int i = 0; i < mEditTexts.size(); i++) {
							mEditTexts.get(i).setText(null);
						}

					} else {
						numbers.clear();
						Toast.makeText(getActivity(), "密码输入错误", Toast.LENGTH_SHORT).show();
					}
				}
			} else {
				if (numbers.size() == 4) {
					tv_cancle.setClickable(true);
					tv_save.setClickable(true);
					tv_save.setTextColor(getResources().getColor(R.color.tv_normal));
					tv_cancle.setTextColor(getResources().getColor(R.color.tv_normal));
				} else {
					tv_cancle.setClickable(false);
					tv_save.setClickable(false);
					tv_cancle.setTextColor(Color.GRAY);
					tv_save.setTextColor(Color.GRAY);
				}
			}
		}

	}

	// 获取加密视频
	private void getPrivateMedia() {
		if (mHandler == null) {
			L.i(TAG, "getPrivateMedia", "mHandler:" + mHandler);
			return;
		}
		mHandler.sendEmptyMessage(LocalActivity.MSG_GET_PRIVATE_MEDIA);
	}

	// 跳到加密视频库的页面
	private void showPrivateVideosView() {
		if (mPrivateVideos.size() > 0) {
			changeViewMode(PRIVATE_MODE_HAS_PRIVATE_MEDIA);
		} else if (mPrivateVideos.size() <= 0) {
			changeViewMode(PRIVATE_MODE_NO_PRIVATE_MEDIA);
		}
	}

	// 自定义键盘是否弹出
	public boolean getKeyBoardisVisible() {
		if (keyBoardView == null) {
			return false;
		}
		return keyBoardView.getVisibility() == View.VISIBLE;
	}

	// 隐藏自定义键盘
	public void hideKeyBoardView() {
		if (keyBoardView != null) {
			keyBoardView.setVisibility(View.GONE);
			if (hasPassword) {
				private_all_bottom.setVisibility(View.GONE);
			} else {
				private_all_bottom.setVisibility(View.VISIBLE);
				ll_local_save_bottom.setVisibility(View.VISIBLE);
			}
		}
	}

	private class CheckBoxChangeListener implements OnCheckedChangeListener {

		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			// 开启私人库
			if (isChecked) {
				isCanclePassWord = false;
				if (mCurrentViewID == NO_LIBRARY_VIEW) {
					changeViewMode(PRIVATE_MODE_SET_PASSWORD);
				} else if (mCurrentViewID == INPUT_PASSWORD_VIEW) {
					changeViewMode(PRIVATE_MODE_INPUT_PASSWORD);
				} else if (mCurrentViewID == SHOW_PRIVATE_VIDEOS_VIEW) {
					keyBoardView.setVisibility(View.GONE);
					showPrivateVideosView();
				}
				numbers.clear();
				for (int i = 0; i < 4; i++) {
					mEditTexts.get(i).setText(null);
				}

			} else {// 关闭私人库
				isCanclePassWord = true;
				if (mCurrentViewID == NO_LIBRARY_VIEW) {
					changeViewMode(PRIVATE_MODE_NO_LIBRARY);
				} else {
					changeViewMode(PRIVATE_MODE_CLOSE_LIBRARY);
				}
			}
		}

	}

	@Override
	public void onPause() {
		// 是为了解决显示私人视频时，切换别的页面 再从别的页面中切换回来 在切换过程中会显示私人视频
		if (needInitData) {// 为了解决私人视频点击切换到播放器时会重新刷新界面
			initData();
		}
		super.onPause();
	}

}
